package com.museum.guide.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.museum.guide.common.result.Result;
import com.museum.guide.entity.CollectionCategory;
import com.museum.guide.service.CollectionCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/category")
public class CollectionCategoryController {

    @Resource
    private CollectionCategoryService categoryService;

    /**
     * 分页查询分类信息
     */
    @GetMapping("/page")
    public Result<Page<CollectionCategory>> page(Page<CollectionCategory> page, String name) {
        return Result.success(categoryService.page(page, name));
    }

    /**
     * 获取分类列表
     */
    @GetMapping("/list")
    public Result<List<CollectionCategory>> list(String name) {
        return Result.success(categoryService.list(name));
    }

    /**
     * 新增分类
     */
    @PostMapping("/add")
    public Result<Void> save(@RequestBody @Valid CollectionCategory category) {
        categoryService.saveCategory(category);
        return Result.success();
    }

    /**
     * 更新分类信息
     */
    @PostMapping("/update")
    public Result<Void> update(@RequestBody @Valid CollectionCategory category) {
        categoryService.updateCategory(category);
        return Result.success();
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/removeById")
    public Result<Void> remove(Long id) {
        categoryService.removeCategory(id);
        return Result.success();
    }
}